package com.javabasic.algorithm.leetcode;

/**
 * @author mir.xiong
 * @version 1.0
 * @description
 * @see {EASY} -- [203. Remove Linked List Elements](https://leetcode-cn.com/problems/remove-linked-list-elements/)
 * @since Created by work on 2021/12/29 10:09 下午
 */
public class RemoveLinkedListElements {

    public ListNode removeElements(ListNode head, int val) {
        ListNode pre = head;
        if (pre == null) {
            return pre;
        }
        ListNode post = pre.next;
        while (post != null) {
            if (post.val == val) {
                pre.next = post;
            } else {
                pre = post;

            }
            post = post.next;
        }
        if (head.val == val) {
            head = head.next;
        }
        return head;
    }

}
